/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.jhnsr.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.jhnsr.entity.TestJhNsr;
import com.thinkgem.jeesite.modules.jhnsr.service.TestJhNsrService;

/**
 * 1Controller
 * @author 1
 * @version 2016-01-14
 */
@Controller
@RequestMapping(value = "${adminPath}/jhnsr/testJhNsr")
public class TestJhNsrController extends BaseController {

	@Autowired
	private TestJhNsrService testJhNsrService;
	
	@ModelAttribute
	public TestJhNsr get(@RequestParam(required=false) String id) {
		//logger.info("前台传过来的id=========  "+id);
		TestJhNsr entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = testJhNsrService.get(id);
		}
		if (entity == null){
			entity = new TestJhNsr();
		}
		return entity;
	}
	
	@RequiresPermissions("jhnsr:testJhNsr:view")
	@RequestMapping(value = {"list", ""})
	public String list(TestJhNsr testJhNsr, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<TestJhNsr> list = testJhNsrService.findListGraph(testJhNsr);
		Page<TestJhNsr> page = testJhNsrService.findPage(new Page<TestJhNsr>(request, response), testJhNsr); 
		
		model.addAttribute("list",list);
		model.addAttribute("page", page);
		
		return "modules/jhnsr/testJhNsrList";
	}

	@RequiresPermissions("jhnsr:testJhNsr:view")
	@RequestMapping(value = "form")
	public String form(TestJhNsr testJhNsr, Model model) {
		model.addAttribute("testJhNsr", testJhNsr);
	//	logger.info("testJhNsr.getNsrsbh=========  "+testJhNsr.getNsrsbh());
	//	logger.info("testJhNsr.id=========  "+testJhNsr.getId());
		return "modules/jhnsr/testJhNsrForm";
	}

	@RequiresPermissions("jhnsr:testJhNsr:edit")
	@RequestMapping(value = "save")
	public String save(TestJhNsr testJhNsr, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, testJhNsr)){
			return form(testJhNsr, model);
		}
		testJhNsrService.save(testJhNsr);
		addMessage(redirectAttributes, "保存纳税人成功");
		return "redirect:"+Global.getAdminPath()+"/jhnsr/testJhNsr/?repage";
	}
	
	@RequiresPermissions("jhnsr:testJhNsr:edit")
	@RequestMapping(value = "delete")
	public String delete(TestJhNsr testJhNsr, RedirectAttributes redirectAttributes) {
		testJhNsrService.delete(testJhNsr);
		addMessage(redirectAttributes, "删除纳税人成功");
		return "redirect:"+Global.getAdminPath()+"/jhnsr/testJhNsr/?repage";
	}
    
}